
// manualCalibDoc.cpp : implementation of the CmanualCalibDoc class
//

#include "stdafx.h"
#include "manualCalib.h"

#include "manualCalibDoc.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CmanualCalibDoc

IMPLEMENT_DYNCREATE(CmanualCalibDoc, CDocument)

BEGIN_MESSAGE_MAP(CmanualCalibDoc, CDocument)
	//ON_COMMAND(ID_LOAD_IMAGES, &CmanualCalibDoc::OnLoadImages)
	//ON_COMMAND(ID_LOAD_ADDTIONALIMAGES, &CmanualCalibDoc::OnLoadAddtionalimages)
	//ON_COMMAND(ID_LOAD_EXTRACTGRIDCORNERS, &CmanualCalibDoc::OnLoadExtractgridcorners)
END_MESSAGE_MAP()


// CmanualCalibDoc construction/destruction

CmanualCalibDoc::CmanualCalibDoc()
{
	// TODO: add one-time construction code here
}

CmanualCalibDoc::~CmanualCalibDoc()
{
}

BOOL CmanualCalibDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}




// CmanualCalibDoc serialization

void CmanualCalibDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}


// CmanualCalibDoc diagnostics

#ifdef _DEBUG
void CmanualCalibDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CmanualCalibDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG


// CmanualCalibDoc commands

// void CmanualCalibDoc::OnLoadImages()
// {
// 	// TODO: Add your command handler code here
// // 	CFileDialog idFile(true);
// // 	string strVers;
// // 
// // 	if (idFile.DoModal()==IDOK)
// // 	{
// // 		strVers=idFile.GetPathName();		
// // 	}
// 	//cvShowImage("image", cvLoadImage(strVers.c_str(), 1));
// 	//AfxMessageBox(_T(strVers.c_str()), MB_OK);
// }

// void CmanualCalibDoc::OnLoadAddtionalimages()
// {
// 	// TODO: Add your command handler code here
// 	CFileDialog iFileDlg(true);
// 	string strFile;
// 
// 	if (iFileDlg.DoModal()==IDOK)
// 	{
// 		strFile=iFileDlg.GetPathName();
// 		if(!m_CalibDataVec->addImage(strFile))
// 		{
// 			AfxMessageBox(_T(strFile.c_str()), MB_OK);
// 		}
// 	}
// 	//cvShowImage("image", cvLoadImage(strVers.c_str(), 1));	
// }

// void CmanualCalibDoc::OnLoadExtractgridcorners()
// {
// 	// TODO: Add your command handler code here
// 	//extract grid corners from a dialog
// }

IplImage *CmanualCalibDoc::getAImage(int index)
{
	if (index < m_CalibDataVec.size())
	{
		return m_CalibDataVec[index]->GetImage();
	}
	return NULL;
}

bool CmanualCalibDoc::ConvertVideo(const string &leftVideoFile, const string &rightVideoFile, SIZE &leftSize, SIZE &rightSize)
{
	//
	CvCapture *leftCap = cvCaptureFromFile(leftVideoFile.c_str());
	if (leftCap)
	{
		leftSize.cx = cvGetCaptureProperty(leftCap, CV_CAP_PROP_FRAME_WIDTH);
		leftSize.cy = cvGetCaptureProperty(leftCap, CV_CAP_PROP_FRAME_HEIGHT);
		cvReleaseCapture(&leftCap);
	}
	else
	{
		return false;
	}	

	CvCapture *rightCap = cvCaptureFromFile(rightVideoFile.c_str());
	if (rightCap)
	{
		rightSize.cx = cvGetCaptureProperty(rightCap, CV_CAP_PROP_FRAME_WIDTH);
		rightSize.cy = cvGetCaptureProperty(rightCap, CV_CAP_PROP_FRAME_HEIGHT);
		cvReleaseCapture(&rightCap);
	}
	else
	{
		return false;
	}
	return true;
}


